package com.webdemo06.util;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateHandler {
	private static SessionFactory sessionFactory;
	private static ThreadLocal<Session> threadLocal=new ThreadLocal<Session>();
	static{
		sessionFactory = new Configuration().configure().buildSessionFactory();
	}
	public HibernateHandler(){}
	public static HibernateHandler newInstance(){
		return new HibernateHandler();
	}
	public Session getCurrentSession(){
		Session session = threadLocal.get();
		if(session==null){
			session = sessionFactory.openSession();
		}
		return session;
	}
	public Session getSession(){
		Session session = sessionFactory.openSession();
		return session;
	}
}
